#!/usr/bin  python
# _*_ coding:utf-8 _*_
"""
----------------------------------
    File Name: adminuser
    Description:
        Author: lhw
        Date: 2020/7/1
-----------------------------------
"""

from rest_framework import serializers
from Admin import models
from rest_framework.exceptions import ValidationError
from Common import bcrypt


class AdminUserModelSerializer(serializers.ModelSerializer):
    class Meta:
        model = models.AdminUser
        fields = ("id", "hospital", "name", "encrypted_password", "email", "role_name", "role")
        extra_kwargs = {
            "role": {
                "write_only": True
            },
            "encrypted_password": {
                "write_only": True
            }
        }

    def validate_encrypted_password(self, value):
        value = bcrypt.Bcrypt.encrypt(value)
        return value

